﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

namespace KTSonline.ajax
{
    public partial class supporter : System.Web.UI.Page
    {
        class SP
        {
            public String yahoo { get; set; }
            public String phone { get; set; }
            public String name { get; set; }

            public SP(String y, String p, String n)
            {
                yahoo = y;
                phone = p;
                name = n;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            Response.Expires = -1;
            Response.ContentType = "text/plain";

            System.Collections.Generic.List<SP> lstSupporter = new System.Collections.Generic.List<SP>();
            lstSupporter.Add(new SP("graybone_online", "Lâm", "01218719731"));
            lstSupporter.Add(new SP("tdduy_khtn", "Duy", "01218719731"));
            lstSupporter.Add(new SP("tsdragon0404", "Sơn", "01218719731"));

            System.Net.WebClient wc = new System.Net.WebClient();
            byte[] originalData;
            System.IO.MemoryStream stream;

            String rs = "";
            foreach (SP supporter in lstSupporter)
            {
                originalData = wc.DownloadData("http://opi.yahoo.com/online?t=5&u=" + supporter.yahoo);
                stream = new System.IO.MemoryStream(originalData);

                System.Drawing.Color color = (new System.Drawing.Bitmap(stream)).GetPixel(7, 7);
                String img = "offline.png";
                if (color.R == 238 && color.G == 224 && color.B == 90)
                    img = "online.png";

                rs += String.Format("<p class='supporter'><a href='ymsgr:sendIM?{0}'><img src='{1}/images/templates/default/{2}'/>{3} - {4}</a></p>",
                    supporter.yahoo, Request.Url.Scheme + "://" + Request.Url.Authority, img, supporter.name, supporter.phone);

            }

            Response.Write(rs);
            Response.End();
        }
    }
}
